
const {ccclass, property} = cc._decorator;

@ccclass
export default class Confeti extends cc.Component {

    @property(cc.SpriteFrame)
    imageAtlas: cc.SpriteFrame = null;

    @property
    is3D:boolean = false
    @property(cc.Node)
    anchDest:cc.Node = null
    @property(cc.Node)
    part:cc.Node = null
    @property
    imgUsedIndex:number = 0
    @property
    imgTypeAmnt:number = 4

    _particle:cc.ParticleSystem3D = null

    onLoad () {
        this._particle = this.part.getComponent(cc.ParticleSystem3D)
    }
    protected onEnable(): void {
        this.is3D ? this._rotEular() : this._rotAngle()
        this._particle.textureAnimationModule.numTilesX = this.imgTypeAmnt
        this._particle.textureAnimationModule.startFrame.constant = this.imgUsedIndex
    }
    start () {

    }
    _rotAngle(){
        let tVec = cc.v2()
        cc.Vec2.normalize(tVec,this.anchDest.getPosition())
        let tAngle = cc.misc.radiansToDegrees(tVec.signAngle(cc.v2(0,1)))
        this._particle.shapeModule.rotation = cc.v3(tAngle,-90)
        // this.part.parent.angle = tAngle
    }
    _rotEular(){

    }
    // update (dt) {}
}
